package com.js.baseview.listview.decoration;

import android.graphics.Rect;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;


public class LinearLayoutItemDecoration extends RecyclerView.ItemDecoration {

    private static final int DEFAULT_OFFSET = 15;
    private int mOffset;

    public LinearLayoutItemDecoration() {
        mOffset = DEFAULT_OFFSET;
    }

    public LinearLayoutItemDecoration(int offset) {
        mOffset = offset;
    }

    @Override
    public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
        final int adapterPosition = parent.getChildViewHolder(view).getAdapterPosition();
        if (adapterPosition == parent.getAdapter().getItemCount() - 1) {
            outRect.set(0, 0, 0, 0);
        } else {
            outRect.set(0, 0, 0, mOffset);
        }
    }
}
